package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.PostBean;
import com.project.bean.UserBean;
import com.project.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("post")
public class PostController {
    @Autowired
    private IPostService postService;

    @RequestMapping("findByItem")
    public IPage<PostBean> findByItem(Integer pageNO, Integer channelId, String theme, String userName, LocalDate startDate,LocalDate endDate){
        return postService.cutByItem(pageNO, channelId, theme, userName, startDate, endDate);
    }

    @RequestMapping("add")
    public String add(PostBean post, HttpServletRequest request){
        UserBean loginUser = (UserBean) request.getSession().getAttribute("loginUser");
        post.setUserId(loginUser.getId());
        postService.add(post);
        return "ok";
    }

    @RequestMapping("findById")
    public  PostBean findById(Integer id){
        return postService.findById(id);
    }
}
